package com.yp.lession.redisqf211.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.yp.lession.redisqf211.entity.Emp;
import com.yp.lession.redisqf211.service.EmpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp")
@Api("员数据操作接口")
public class EmpController {
    @Autowired
    private EmpService empService;

    @ApiOperation("获取所有员工数据")
    @GetMapping("/list")
    public List<Emp> getList() throws JsonProcessingException {
    return empService.getList();
    }

    @ApiOperation("获得单个员工数据")
    @GetMapping("/list/{eno}")
    public Emp emp(@PathVariable Integer eno) throws JsonProcessingException {
        return empService.empById(eno);
    }

    @ApiOperation("修改员工数据")
    @PostMapping("/emp")
    public String update(@RequestBody Emp emp) throws JsonProcessingException {
        boolean ans = empService.updateEmp(emp);
        if (ans) {
            return "修改成功";
        }
        return "修改失败";
    }

}
